﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace LabChecker.Models.Programs.Exceptions
{
    public class RuntimeError : Exception
    {
        private string _exceptionInformation;

        public RuntimeError(Exception innerException)
            : base("runtime error", innerException)
        {
            var trace = new StackTrace(innerException, true);
            Line = trace.GetFrame(0).GetFileLineNumber();
            Column = trace.GetFrame(0).GetFileColumnNumber();
        }

        public RuntimeError(string exceptionInformation)
        {
            _exceptionInformation = exceptionInformation;
        }        

        public int Line { get; private set; }

        public int Column { get; private set; }

        public string ErrorMessage 
        { 
            get 
            {
                return (InnerException != null) ? (InnerException.GetType().Name + ": " + InnerException.Message) : _exceptionInformation; 
            } 
        }
    }
}
